home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / vol_200 / 233_01 / dskrpk.c < prev    next >
Text File  |  1987-06-29  |  22KB  |  614 lines

  1. /******************************************************************/
  2. /*     Directory repack                                           */
  3. /*     written by Rich Karas for the public domain                */
  4. /*     rev 1.0 1/23/86                                            */
  5. /*                                                                */
  6. /*                                                                */
  7. /*                                                                */
  8. /******************************************************************/
  9.  
  10. #include "stdio.h"
  11. #include "customiz.h"
  12. #define MAXSIZE 16383
  13. #define MINSIZE 8192
  14. #define MAXDIRS 512
  15. char fat[MINSIZE];
  16.      /*  these are global variables */
  17.  
  18. int drive,num_sect,begin,status,error,directory[MAXSIZE];
  19. unsigned int fat_strt,dir_strt,data_area,dir_len;
  20. unsigned int byte_sect,sect_unit,reserv_strt,no_fat,fat_sect,no_root;
  21. unsigned int sect_image,media,sect_track,no_heads,no_hidden;
  22. int *bufptr;
  23. #define UNDERL "\033\133\064\155\0"
  24. #define NORMAL "\033\133\155\0"
  25. #define REVERSE "\033\133\067\155\0"
  26. #define BOLD "\033\133\061\155\0"
  27. #define BLINK "\033\133\065\155\0"
  28. #define CLRSCR "\033\133\062\112\0"
  29. #define ERASELN "\033\133\113\0"
  30. #define XTIME 30
  31. #define CPOS1 "\033\133\065\073\062068\110\0"
  32. /******************************************************************/
  33. /*                                                                */
  34. /*    Introduction is a procedure that prints using ansii         */
  35. /*    ESCAPE codes to implement blinking and cusor position.      */
  36. /*                                                                */
  37. /*                                                                */
  38. /*                                                                */
  39. /******************************************************************/
  40.  
  41. intro()             /* introduces who we are */
  42. {
  43.  printf("%s",CLRSCR);
  44.  printf("%s",CPOS1);
  45.  printf("%s%s    DIRECTORY REPACK %s\n",BOLD,BLINK,NORMAL);
  46.  printf("\n\n\n\n\n\n");
  47.  printf("                      Rich Karas\n");
  48.  printf("                      14 Wells Road\n");
  49.  printf("                      Flemington,NJ 08822\n");
  50.  printf("                      Voice 201-782-0639\n");
  51.  printf("                      Data  201-782-7640\n");
  52.  printf("\n\n\n\n\n");
  53.  printf("            Public Domain Software 1986, Richard Karas \n");
  54.  printf("                        REV 1.0 1/23/86");
  55.  sleep(XTIME);
  56.  printf("%s",CLRSCR);
  57. }
  58. /******************************************************************/
  59. /*                                                                */
  60. /*     Select drive is an assembly language program which         */
  61. /*     calls DOS system functions to find out how many drives     */
  62. /*     are present.                                              */
  63. /*                                                                */
  64. /*                                                                */
  65. /******************************************************************/
  66.  
  67. select_drive()
  68. {
  69.   register int x;
  70. #asm
  71.      push ds
  72.      push ss
  73.      push ax
  74.      push dx
  75.      mov  ah,19h
  76.      int 21h
  77.      mov dl,al
  78.      mov ah,0eh
  79.      int 21h
  80.      mov di,ax
  81.      pop dx
  82.      pop ax
  83.      pop ss
  84.      pop ds
  85. #endasm
  86.     return( x & 0177);
  87. }
  88. /******************************************************************/
  89. /*                                                                */
  90. /*      Reset dsk does just what it says,using                    */
  91. /*      another DOS system call.                                  */
  92. /*                                                                */
  93. /*                                                                */
  94. /*                                                                */
  95. /******************************************************************/
  96.  
  97.  
  98. reset_dsk()
  99. {
  100. #asm
  101.      push ds
  102.      push ss
  103.      push ax
  104.      push dx
  105.      mov  ah,0dh
  106.      int 21h
  107.      pop dx
  108.      pop ax
  109.      pop ss
  110.      pop ds
  111. #endasm
  112. }
  113. /******************************************************************/
  114. /*                                                                */
  115. /*      Disk read performs absolute disk reads through            */
  116. /*      the system calls. IT reads X number of sectors begining   */
  117. /*       at sector specified.                                      */
  118. /*                                                                */
  119. /*                                                                */
  120. /******************************************************************/
  121.  
  122.  
  123. disk_read()  /* routine to perform absolute disk read */
  124. {
  125. #asm
  126.      push ds
  127.      push ax
  128.      push bx
  129.      push cx
  130.      push dx
  131.      mov  ax,DS:WORD PTR drive
  132.      mov  bx,offset bufptr
  133.      mov  dx,[bx]
  134.      mov  bx,dx
  135.      mov  cx,DS:WORD PTR num_sect
  136.      mov  dx,DS:WORD PTR begin
  137.      int  25h
  138.      pushf
  139.      mov  DS:WORD PTR error,ax
  140.      pop  ax
  141.      mov  DS:WORD PTR status,ax
  142.      popf
  143.      pop  dx
  144.      pop  cx
  145.      pop  bx
  146.      pop  ax
  147.      pop  ds
  148. #endasm
  149. }
  150. /******************************************************************/
  151. /*                                                                */
  152. /*            Same as read, but writes to disk.                   */
  153. /*                                                                */
  154. /*                                                                */
  155. /*                                                                */
  156. /*                                                                */
  157. /******************************************************************/
  158.  
  159. disk_write()  /* routine to perform absolute disk write */
  160. {
  161. #asm
  162.      push ds
  163.      push ax
  164.      push bx
  165.      push cx
  166.      push dx
  167.      mov  ax,DS:WORD PTR drive
  168.      mov  bx,offset bufptr
  169.      mov  dx,[bx]
  170.      mov  bx,dx
  171.      mov  cx,DS:WORD PTR num_sect
  172.      mov  dx,DS:WORD PTR begin
  173.      int  26h
  174.      pushf
  175.      mov  DS:WORD PTR error,ax
  176.      pop  ax
  177.      mov  DS:WORD PTR status,ax
  178.      popf
  179.      pop  dx
  180.      pop  cx
  181.      pop  bx
  182.      pop  ax
  183.      pop  ds
  184. #endasm
  185. }
  186. /******************************************************************/
  187. /*                                                                */
  188. /*        Operator enters the disk dirve to repack.               */
  189. /*                                                                */
  190. /*                                                                */
  191. /*                                                                */
  192. /*                                                                */
  193. /******************************************************************/
  194.  
  195. prompt(k)  /* prompts for operator entry of drive to dir repack */
  196. int k;
  197. {
  198.   char j,num;
  199.   int i;
  200.   j=65;
  201.   drive=0;
  202.   printf("Please select disk drive to repack directories \n");
  203.   printf("          ");
  204.   for(i=0;i<k;i++)
  205.      {  printf("  %c",j);
  206.         j=j+1;
  207.         }
  208.   printf("\n Drive = ");
  209.   scanf("%c",&num);      /* gets operator value and converts to upper */
  210.   num=toupper(num);
  211.   printf("\n\n");
  212.   i=num-65;
  213.   if(i>k) {
  214.       printf(" drive selected is not configured in system");
  215.       exit(0);
  216.       }
  217.   else
  218.      drive=i;
  219. }
  220. /******************************************************************/
  221. /*         This procedure analysis the media discription and      */
  222. /*         performs some math. It also and displays these         */
  223. /*         attributes.                                            */
  224. /*         It reads the boot sector byte offset 11-29.            */
  225. /*                                                                */
  226. /*                                                                */
  227. /******************************************************************/
  228.  
  229.  
  230. attrib()
  231. {
  232.   double val1[1],val2[1],val3[1],val4[1],val5[1];
  233.   char l1[100];
  234.   int temp,i;
  235.   fat_sect=directory[11];      /* ref dos manual for explanation */
  236.   sect_track=directory[12];
  237.   no_heads=directory[13];
  238.   no_hidden=directory[14];
  239.   reserv_strt=directory[7];
  240.   m